# python -m project_root.api.api_personal
from .api_token import Token 
import requests


class Api_Personal(Token):

    # id 说明： 1.返回操作角色 2.返回数据角色 3.返回个人信息
    def get_userinfo(self,id=1):
        try:
            url = 'http://hxzhan.rtcloud.com:32111/tm/roles/user/info'
           
            response = requests.get(url=url,headers=self.get_header())
            assert response.status_code == 200
            self.logger.info(f'调用接口 get_userinfo 成功 ,id = {id}')
            values = ''
            personal_values = []
            if id ==1:
                for value in response.json()['data']['ctrl_role_list']:
                    values = values + value['roleName']
                return values
            elif id == 2:
                for value in response.json()['data']['data_role_list']:
                    values = values + value['roleName']
                return values
            elif id == 3:
                keys = ['real_name','id_card','gender','phone','email']
                for key in keys:
                    if key == 'gender':
                        if response.json()['data'][key] == 1:
                            personal_values.append('男')
                        elif response.json()['data'][key] == 2:
                            personal_values.append('女')
                    else:
                        personal_values.append(response.json()['data'][key])
                return personal_values
        except Exception as e:
            self.logger.info('调用接口 get_userinfo 失败 ')
        
